#include "logger.h"
#include <stdio.h> /* needed for vfprintf */

/**
 * author: Assaf Paz.
 * 
 * initiateLogger
 * 
 * initiate the logger
 */
void initiateLogger()
{
	logMessage("initiateLogger:Logger has started successfully\n");
}

/**
 * author: Assaf Paz.
 * 
 * logMessage
 * 
 * format - string format to add to the log, same as used in printf
 * ... - variables to fit the format, same as used in printf
 * 
 * add a message to the log
 */
void logMessage(const char* format,...)
{ 
	va_list ap;
	va_start(ap, format);
	vfprintf(stdout, format, ap);
	va_end(ap);
}

/**
 * author: Assaf Paz.
 * 
 * closeLogger
 * 
 * shutdown the logger
 */
void closeLogger()
{
	logMessage("closeLogger:Logger has shutdown successfully\n");
}

/**
 * author: Assaf Paz.
 * 
 * removeUnprintable
 * 
 * oldString - string with unprintable chars
 * size - true size of oldString (to avoid '\0' premature ending)
 * newString - preMalloced result string
 * 
 * remove unprintable chars from a string so will be able to be fully printed.
 * newString is also the returned value
 */
char* removeUnprintable(char* oldString, unsigned int size, char* newString)
{
	int i=0;
	for (; i<size ; ++i)
	{
		if (oldString[i]!='\0' && oldString[i]!='\n')
		{
			newString[i]=oldString[i];
		}
		else
		{
			newString[i]=' ';
		}
	}
	newString[i]='\0';
	return newString;
}
